package com.example.test;

import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.TextView;

public class AutoCompleteActivity extends Activity implements TextWatcher {
	AutoCompleteTextView autoCompleteTextView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.autocomplete);
		autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.edit);
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
				R.layout.layout_auto_comnplete, WORLDCUP2010);
		autoCompleteTextView.setAdapter(adapter);
		autoCompleteTextView.addTextChangedListener(this);
	}

	static final String[] WORLDCUP2010 = new String[] { "Algeria", "Argentina",
			"Australia", "Brazil", "Cote d'Ivoire", "Cameroon", "Chile",
			"Costa Rica", "Denmark", "England", "France", "Germany", "Ghana",
			"Greece", "Honduras", "Italy", "Japan", "Netherlands",
			"New Zealand", "Nigeria", "North Korea", "Paraguay", "Portugal",
			"Serbia", "Slovakia", "Slovenia", "South Africa", "South Korea",
			"Spain", "Switzerland", "United States", "Uruguay" };

	@Override
	public void afterTextChanged(Editable s) {
		// TODO Auto-generated method stub

	}

	@Override
	public void beforeTextChanged(CharSequence s, int start, int count,
			int after) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onTextChanged(CharSequence s, int start, int before, int count) {
		TextView textView = (TextView) findViewById(R.id.country);
		textView.setText(autoCompleteTextView.getText());
	}
}
